home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / UNIX / DATABASE / INDEX / MAIN.C < prev    next >
C/C++ Source or Header  |  1992-11-23  |  2KB  |  113 lines

  1. #ifndef lint
  2. static char *RCSid = "$Header: /u5/davy/progs/index/RCS/main.c,v 1.1 89/08/09 11:06:42 davy Exp $";
  3. #endif
  4. /*
  5.  * main.c - main routine for index program.
  6.  *
  7.  * David A. Curry
  8.  * Research Institute for Advanced Computer Science
  9.  * Mail Stop 230-5
  10.  * NASA Ames Research Center
  11.  * Moffett Field, CA 94035
  12.  * davy@riacs.edu
  13.  *
  14.  * $Log:    main.c,v $
  15.  * Revision 1.1  89/08/09  11:06:42  davy
  16.  * Initial revision
  17.  * 
  18.  */
  19. #include <sys/param.h>
  20. #include <curses.h>
  21. #include <stdio.h>
  22. #include "defs.h"
  23.  
  24. int    igncase = 0;            /* non-zero if -i flag given    */
  25. int    verbose = 0;            /* non-zero if -v flag given    */
  26.  
  27. char    *pname;                /* program name            */
  28. char    dbasedir[MAXPATHLEN];        /* path to database directory    */
  29.  
  30. main(argc, argv)
  31. char **argv;
  32. int argc;
  33. {
  34.     char *database, *filter, *pattern;
  35.  
  36.     pname = *argv;
  37.     database = filter = pattern = NULL;
  38.  
  39.     /*
  40.      * Process arguments.
  41.      */
  42.     while (--argc) {
  43.         if (**++argv == '-') {
  44.             switch (*++*argv) {
  45.             case 'f':            /* filter    */
  46.                 if (--argc <= 0)
  47.                     usage();
  48.  
  49.                 filter = *++argv;
  50.                 continue;
  51.             case 'i':            /* ignore case    */
  52.                 igncase++;
  53.                 continue;
  54.             case 'v':            /* verbose    */
  55.                 verbose++;
  56.                 continue;
  57.             }
  58.         }
  59.  
  60.         /*
  61.          * database argument is first.
  62.          */
  63.         if (database == NULL) {
  64.             database = *argv;
  65.             continue;
  66.         }
  67.  
  68.         /*
  69.          * pattern argument is next.
  70.          */
  71.         if (pattern == NULL) {
  72.             pattern = *argv;
  73.             continue;
  74.         }
  75.  
  76.         usage();
  77.     }
  78.  
  79.     /*
  80.      * Get the path of the database directory.
  81.      */
  82.     set_dbase_dir();
  83.  
  84.     /*
  85.      * If they didn't specify a database, put them in
  86.      * the selection routine.
  87.      */
  88.     if (database == NULL)
  89.         database = select_db();
  90.  
  91.     /*
  92.      * Open the database and read it in.
  93.      */
  94.     read_idxfile(database);
  95.     read_dbfile(database);
  96.  
  97.     /*
  98.      * If they didn't specify a pattern, go to the
  99.      * main menu.  Otherwise, search the database
  100.      * for the pattern, and print the results.
  101.      */
  102.     if (pattern == NULL) {
  103.         main_menu(database);
  104.         reset_modes();
  105.     }
  106.     else {
  107.         search_db(pattern);
  108.         print_db(database, filter);
  109.     }
  110.  
  111.     exit(0);
  112. }
  113.